# 集合 无序去重的数据容器
my_set = {4, 3, 4, 3, 1, 4, 4, 2, 2}
my_set_empty = set()
print(my_set, type(my_set))
print(my_set_empty)

# 添加新元素
my_set.add(33)
my_set.add(2)
print(my_set)

# 去除元素
my_set.remove(4)
print(my_set)

# 随机取出元素(会修改集合)
my_set = {1, 3, "hello", "haha", "where", False, "hehe"}
my_set2 = {"i am", "new", "true", "world"}
my_set3 = {3, 44, 3, 66, 2, 7, 6, 8}
element = my_set.pop()
print(element, my_set)
element = my_set2.pop()
print(element, my_set2)
element = my_set3.pop()
print(element, my_set3)

# 清空集合
my_set.clear()
print(my_set)

# 获得去除两集合交集后的集合(取差集A - B)
my_set = {1, 3, 4, 5}
my_set2 = {3, 2, 4}
my_set3 = my_set.difference(my_set2)
print(my_set, my_set2, my_set3)  # 不修改原集合

# 在集合中去除两个集合的交集(相当于上面方法的会修改版本)
my_set.difference_update(my_set2)
print(my_set, my_set2)

# 合并集合
my_set3 = my_set.union(my_set2)
print(my_set, my_set2, my_set3)

# 获取集合长度
print(len(my_set3))

# 集合的遍历
# 集合不支持[]访问,使用for循环遍历
for element in my_set3:
    print(element, end=' ')

# 集合元素无序无序无序！！！数字也不是按升序存储的，是计算哈希值存储的
my_set = {1, 2, 3, 4, 64}
print(my_set)
